package erfgame.core.util;

import org.junit.Before;
import org.junit.Test;

import erfgame.core.Rotation;

public class PerformanceTester {

	private int amount;

	@Before
	public void init() {
//		ColorUtils.atan2sin(0, 0, Rotation.degrees0);
//		amount = MathFP.PI;
	}
	
	@Test
	public void testDivide() {
		for( int i=amount; i>1; i-- ) {
			int j = 100 / i;
			donothing( j );
		}
	}

	@Test
	public void testDivideReversed() {
		for( int i=amount; i>1; i-- ) {
			int j = i / 100;
			donothing( j );
		}
	}

	@Test
	public void testShiftDown() {
		for( int i=amount; i>1; i-- ) {
			int j = 100 >> i;
			donothing( j );
		}
	}

	@Test
	public void testShiftDownReversed() {
		for( int i=amount; i>1; i-- ) {
			int j = i >> 100;
			donothing( j );
		}
	}

	@Test
	public void testSquare() {
		for( int i=amount; i>1; i-- ) {
			int j = i * i;
			donothing( j );
		}				
	}

	@Test
	public void testMultiply() {
		for( int i=amount; i>1; i-- ) {
			int j = 100 * i;
			donothing( j );
		}				
	}
	
	@Test
	public void testShiftUp() {
		for( int i=amount; i>1; i-- ) {
			int j = 100 << i;
			donothing( j );
		}		
	}
	
	@Test
	public void testMod() {
		for( int i=amount; i>1; i-- ) {
			int j = 100 % i;
			donothing( j );
		}						
	}

	@Test
	public void testModReversed() {
		for( int i=amount; i>1; i-- ) {
			int j = i % 100;
			donothing( j );
		}						
	}

	@Test
	public void testMask() {
		int mask = 0xFF;
		for( int i=amount; i>1; i-- ) {
			int j = mask & i;
			donothing( j );
		}		
	}

	@Test
	public void testDivideBy16() {
		testDivide( 16 );
	}
	
	@Test
	public void testMathFPSin() {
		for( int i=amount; i>1; i-- ) {
//			int l = MathFP.toFP(i);
//			l = MathFP.sin( l );
//			int v = (int)MathFP.toInt( l );
//			donothing( v );
		}		
	}

	@Test
	public void testMathFPCos() {
		for( int i=amount; i>1; i-- ) {
//			int l = MathFP.toFP(i);
//			l = MathFP.cos( l );
//			int v = (int)MathFP.toInt( l );
//			donothing( v );
		}		
	}

	@Test
	public void testMathFPAtan2OnTop() {
		for( int i=amount; i>1; i-- ) {
//			int l = MathFP.toFP(i);
//			int d = MathFP.toFP(20);
//			l = MathFP.atan2( l, d );
//			int v = (int)MathFP.toInt( l );
//			donothing( v );
		}		
	}

	@Test
	public void testMathFPAtan2OnBottom() {
		for( int i=amount; i>1; i-- ) {
//			int l = MathFP.toFP(i);
//			int d = MathFP.toFP(20);
//			l = MathFP.atan2( d, l );
//			int v = (int)MathFP.toInt( l );
//			donothing( v );
		}		
	}

	@Test
	public void testSin() {
		for( int i=amount; i>1; i-- ) {
			double d = Math.sin( (double)i );
			donothing( d );
		}		
	}

	@Test
	public void testCos() {
		for( int i=amount; i>1; i-- ) {
			double d = Math.cos( (double)i );
			donothing( d );
		}		
	}

	@Test
	public void testATan2OnTop() {
		for( int i=amount; i>1; i-- ) {
			double d = Math.atan2( (double)i, 5D );
			donothing( d );
		}		

	}

	@Test
	public void testATan2OnBottom() {
		for( int i=amount; i>1; i-- ) {
			double d = Math.atan2( 5D, (double)i );
			donothing( d );
		}		
	}

	public void testDivide( int by ) {
		for( int i=amount; i>1; i-- ) {
			int j = i / by;
			donothing( j );
		}
		
	}
	

//	@Test
//	public void testColorUtilCos() {
//		for( int i=amount; i>1; i-- ) {
//			int l = i;
//			l = ColorUtils.cos( l );
//			int v = (int)MathFP.toInt( l );
//			donothing( v );
//		}		
//	}
//
//	@Test
//	public void testColorUtilSin() {
//		for( int i=amount; i>1; i-- ) {
//			int l = i;
//			l = ColorUtils.sin( l );
//			int v = (int)MathFP.toInt( l );
//			donothing( v );
//		}		
//	}

	@Test
	public void testColorUtilAtan2Sin() {
		for( int i=amount; i>1; i-- ) {
//			int l = i;
//			l = ColorUtils.atan2sin( 2, 3 );
//			int v = (int)MathFP.toInt( l );
//			donothing( v );
		}		
	}

	protected void donothing( int j ) {
	}
	
	protected void donothing( double d ) {
	}
}
